package com.boot.scheduled;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Wuxiang on 2017/7/26.
 */
@Component
public class ScheduledTasks {
    private static final SimpleDateFormat dateFormat
            = new SimpleDateFormat("HH:mm:ss");

    @Scheduled(cron = "*/10 * * * * *")
    public void cron() {
        System.out.println("现在时间：" + dateFormat.format(new Date()));
        System.out.println("every 10 sec by cron\n");
    }

    @Scheduled(fixedDelay = 5000)
    public void fixedDelay() {
        System.out.println("现在时间：" + dateFormat.format(new Date()));
        System.out.println("every 5 sec by fixedDelay\n");
    }

    @Scheduled(fixedRate = 2000)
    public void fixedRate() {
        System.out.println("现在时间：" + dateFormat.format(new Date()));
        System.out.println("every 2 sec by fixedRate\n");
    }

}